package codeForce;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class B_EraseFirstorSecondLetter {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                set.clear();
                int tmp = sc.nextInt();
                String s = sc.next();
                calNum(s,set);
                System.out.println(set.size());
            }
        }
        public static void calNum(String s,HashSet<Integer> hashSet){
            if(s==null||s.length()==0){
                return;
            }
            int hash = s.hashCode(); // 计算字符串的哈希值
            if(!hashSet.contains(hash)){
                hashSet.add(hash);
            }
            if(s.length()>0){
                calNum(s.substring(1),hashSet);
            }
            if(s.length()>1){
                calNum(s.substring(0,1)+s.substring(2),hashSet);
            }
        }

}
